package com.yjd.bi.etl.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yjd.comm.enums.RpcJobExecStatus;
import com.yjd.job.BaseJob;
import com.yjd.job.service.IJobRemoteService;
import com.yjd.comm.util.SpringContextHolder;




/**
 * @Description: JOB对外服务接口
 * @author SongJian devpage@126.com
 * @date 2015-4-29
 */
@Service("jobRemoteService")
public class JobRemoteService implements IJobRemoteService{

	private final Logger logger = LoggerFactory.getLogger(JobRemoteService.class);
	
	@Override
	public int call(String jobType) throws Exception {
		try {
			//这一步的意义是用Class去检查Job类到底存在不存在,不要删除
			String JobName = Class.forName(jobType).getSimpleName();
			String beanName = JobName.substring(0,1).toLowerCase()+JobName.substring(1);
			BaseJob baseJob = SpringContextHolder.getBean(beanName);
			int execResult = baseJob.execute();
			if(execResult==RpcJobExecStatus.SUCCESS.getValue()){
				return 1;
			}else{
				return execResult;
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			return -999;
		}
	}
 

}